<?php

class spGuiListBox extends spDiv
{
	private $insideDiv;

	public function __construct( $param=array() )
	{
		parent::__construct();
		parent::addClass( "spGuiListBox" );

		$this->insideDiv = new spDiv;
		$this->insideDiv->setClass( "spGuiListBoxInsideDiv" );
		parent::addChild( $this->insideDiv );

		if ( isset($param["noborder"]) && $param["noborder"]=="true" )
			$this->insideDiv->addStyle( "border", "0" );
		
		if ( isset($param["items"]) )
			$this->addItems( $param["items"] );
			
		if ( isset($param["width"]) )
			$this->setWidth( $param["width"] );

		if ( isset($param["height"]) )
			$this->setHeight( $param["height"] );

		if ( isset($param["min-width"]) )
			$this->setMinWidth( $param["min-width"] );
			
		if ( isset($param["id"]) )
			$this->setId( $param["id"] );
	}
	
	public function addItems( $items )
	{
		foreach ( $items as $item )
		{
			$this->addItem( $item );
		}
	}
	
	public function addItem( $item )
	{
		if ( $item instanceof spGuiListBoxItem )
		{
			$this->onAddItem( $item );
			return;
		}
		
		$this->onAddItem( new spGuiListBoxItem(array(
			"content" => $item
		)));
	}
	
	protected function onAddItem( $item )
	{
		$this->insideDiv->addChild( $item );
	}
	
	public function setWidth( $width )
	{
		parent::addStyle( "width", $width );
	}
	public function setMinWidth( $width )
	{
		parent::addStyle( "min-width", $width );
	}

	public function setHeight( $height )
	{
		$this->insideDiv->addStyle( "height", $height );
	}
	
	public function setId( $id )
	{
		parent::setId( $id );
	}
}

?>